<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('质量检验')"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">质检人</label>
                        <div class="layui-input-inline">
                            <!--<input type="text" class="layui-input" name="zjr" id="zjr"/>-->
                            <input type="text" name="zjr" id="zjr" placeholder="质检人" lay-verify="required" autocomplete="off" class="layui-input "/>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">日期时间选择器</label>
                        <div class="layui-input-inline">
<!--
                            <input type="text" class="layui-input"  placeholder="yyyy-MM-dd HH:mm:ss">
-->
                            <input type="text" name="zjr" id="zjsj" name="zjsj" placeholder="yyyy-MM-dd HH:mm:ss" lay-verify="required" autocomplete="off" class="layui-input "/>

                        </div>
                    </div>


                  <!--  <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload">搜索</a>
                    </div>-->

                </form>

                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>

                <div class="group-button" id="toolbar">
                    <a class="layui-btn layui-btn-sm layui-btn-normal eidtBtn">
                        <i class="layui-icon">&#x1005;</i> 保存并修改
                    </a>
                </div>

                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                    <input type="hidden" class="layui-input" th:value="${sszjdid}" id="sszjdid"/>
                </section>
            </div>
        </div>
    </div>
</div>
</body>


<div th:include="public/public_js::public_js"></div>
<style type="text/css">
    .moreBtn {
        width: 50px;
        height: 20px;
        text-align: center;
        color: #fff;
        line-height: 20px;
        background-color: #eee;
        position: relative;
        margin: 0 auto;
        cursor: pointer;
    }

    .moreBtn:before {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(30deg);
        background: #eee;
        border-top-left-radius: 8px;
        left: -20px;
        top: 0;
    }

    .moreBtn:after {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(-30deg);
        background: #eee;
        border-top-right-radius: 8px;
        top: 0;
        right: -20px;
    }

</style>
<script>
    $("form input[type=text]").each(function () {
        this.value = $.trim(this.value);

        $(document).ready(function () {//通用方法去输入框前后空格
            $("form").on("change", function () {
                $("form input[type=text]").each(function () {
                    this.value = $.trim(this.value);
                });
            })
        });
    });

    console.log("我来了！！ ");
    $(".moreBtn").on("click",function () {
        $(".moreSearch").toggle();
    })
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate'], function () {
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        zzpUtils.select2({
            elem: ".js-data-example-ajax",
            url: "/wmsrrailwayplatform/list"
        });
        window.operateEvent = {
            "click .layui-btn-primary": function (e, value, row, index) {
                alert(row.mc);
            },
            "click #check": function (e, value, row, index) {
                checkDialog(row.ysdh);
            },
           /* "click #hege": function (e, value, row, index) {//合格
                hegeDialog(row.ysdh);
            },
            "click #buhege": function (e, value, row, index) {//不合格
                buhegeDialog(row.ysdh);
            },*/
        };

        /*顶部按钮多选启用*/
        $("#btn_qi").on('click', function () {
            var index = 0;
            var $rows = $table.bootstrapTable('getSelections');
            //判断选中的库区里是否有已经启用的
            for (var i = 0; i < $rows.length; i++) {
                if ($rows[i].jhzt == 1) {
                    index++;
                }
            }
        })

        //日期时间选择器
          laydate.render({
            elem: '#zjsj'
            ,type: 'datetime'
          });

        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            url: '/wmsqualityinspectionlistdetailed/list/'+$("#sszjdid").val(),
            columns: [{
                field: '',
                checkbox: true
            }, {
                field: 'zjsf',
                title: '质检方式'
            }, {
                field: 'goodsbh',
                title: '货品编号'
            }, {
                field: 'goodsmc',
                title: '货品名称'
            }, {
                field: 'bzmc',
                title: '包装名称'
            }, {
                field: 'dwmc',
                title: '单位名称'
            }, {
                field: 'shsl',
                title: '收获数量'
            }, {
                field: 'yjsl',
                title: '应检数量',

                formatter: function (value, row, index) {
                    if (row.zt == 1) {
                        return [
                            '<a class="layui-btn layui-btn-primary layui-btn-xs" >合格</a>'
                        ].join('')
                    } else  if (row.zt == 2) {
                        return [
                            '<a class="layui-btn layui-btn-primary layui-btn-xs" >不合格</a>'
                        ].join('')
                    }
                }
            }, {
                field: 'ypsl',
                title: '样品数量',
                formatter: operateFormatterNumber
            }, {
                field: 'show_zt',
                title: '质检状态'
            }, {
                field: 'pc',
                title: '批次'
            }, {
                field: 'scrq',
                title: '生产日期'
            },{
                field: 'caozuo',
                title: '操作',
                events: operateEvent,
                formatter: operateFormatter
            }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
        });


        function operateFormatter(value, row, index) {

       /* if(row.zt=1){*/
        return [
                '<a class="layui-btn layui-btn-normal layui-btn-xs" id="hege'+index+'" onclick="changehege('+index+','+row.zt+',\''+row.id+'\')">合格</a>',
                '<a class="layui-btn layui-btn-danger layui-btn-xs" id="buhege" onclick="changebuhege('+index+','+row.zt+',\''+row.id+'\')">不合格</a>'
            ].join('')
       /* }*/
     }

     function operateFormatterNumber (value,row,index) {
            return [
                '<input type="text"  id="dongjieNumber'+index+'" onblur="changett('+index+','+row.ypsl+',\''+row.id+'\')"  value="'+ value +'"/>',
            ].join('')
        }

        $(".inline-search-btn").on('click', function () {
            zzpUtils.refreshTable("#table");
        })



        $(".eidtBtn").on('click',function () {
            var rows = $("#table").bootstrapTable('getSelections');
            var detailed=[];
            var pass={};
            var pass2={};

             pass.zjr=$("#zjr").val();
             pass.zjsj=$("#zjsj").val();

            for(var i=0;i<rows.length;i++){
                pass={};
                pass.sszjdid=rows[i].sszjdid;
                pass.asnmxid=rows[i].asnmxid;
                pass.asnid=rows[i].asnid;
                pass2={};
                pass2.ypsl=rows[i].ypsl;
                pass2.asnmxid=rows[i].asnmxid;
                pass2.zt=rows[i].zt;
                pass2.id=rows[i].id;
                pass2.sszjdid=rows[i].sszjdid;
                pass2.OldNumber_yjsl=rows[i].yjsl;
                detailed.push(pass2);
                pass.detailed=detailed;
            }
            if(rows.length == 0){
                layer.msg("请选择一条进行修改");
            }else{
                console.log(pass);
                zzpUtils.action({
                    url:"/wmsqualityinspectionlistdetailed/addZljy",
                    data:JSON.stringify(pass),
                    success:function (data) {
                        setTimeout(function(){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            top.layer.msg(data.title);
                        },500);
                    },error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                });
            }
        })


    });

    function changett(index,sl,id){
        var dongjiedata = $('#dongjieNumber'+index).val();
        if (/^\d+$/.test(dongjiedata)) {
            if (parseInt(dongjiedata) <= parseInt(sl)) {
                $('#dongjieNumber'+index).val(dongjiedata);
            }else{
                $('#dongjieNumber'+index).val(sl);
            }
        }
    }

    function changehege(index,zt,id){
        var dongjiedata = $('#hege'+index).val();
        alert(zt)
        var tt = $('#hege'+index).val("1");
        alert(tt)
    }

    function changebuhege(index,zt,id){
        var dongjiedata = $('#hege'+index).val();
        alert(+zt)
    }

</script>
</html>